Conditions | 1 |
Paths | 1 |
Total Lines | 122 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
241 | function Context (lvl, writer) { |
||
242 | var self = this |
||
243 | var writers |
||
244 | var levels |
||
245 | |||
246 | function reset (lvl, writer) { |
||
247 | writers = new TreeNode(writer || Logger) |
||
248 | levels = new TreeNode(level(lvl) || Level.Info) |
||
249 | } |
||
250 | |||
251 | reset(lvl, writer) |
||
252 | |||
253 | this.reset = reset |
||
254 | |||
255 | function path (name) { |
||
256 | return (name || '').toString().split('.').filter(function (_) { return _ }) |
||
257 | } |
||
258 | |||
259 | this.path = path |
||
260 | |||
261 | /** |
||
262 | * Retrieves level for provided logger |
||
263 | * |
||
264 | * @param {string} name |
||
265 | * @return {Level} |
||
266 | */ |
||
267 | this.getLevel = function (name) { return levels.retrieve(path(name)) } |
||
268 | |||
269 | /** |
||
270 | * Retrieves level for provided logger |
||
271 | * |
||
272 | * @deprecated |
||
273 | * |
||
274 | * @param {string} name |
||
275 | * @return {Level} |
||
276 | */ |
||
277 | this.getThreshold = this.getLevel |
||
278 | |||
279 | /** |
||
280 | * Sets level for specified logger |
||
281 | * |
||
282 | * @param {string} [name] |
||
283 | * @param {Level} lvl |
||
284 | */ |
||
285 | this.setLevel = function (name, lvl) { |
||
286 | if (!lvl) { |
||
287 | lvl = name |
||
288 | name = null |
||
289 | } |
||
290 | levels.put(path(name), level(lvl)) |
||
291 | return self |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * Sets level for specified logger |
||
296 | * |
||
297 | * @deprecated |
||
298 | * |
||
299 | * @param {string} [name] |
||
300 | * @param {Level} level |
||
301 | */ |
||
302 | this.setThreshold = this.setLevel |
||
303 | |||
304 | /** |
||
305 | * Removes and returns level at provided path |
||
306 | * |
||
307 | * @param {string} name |
||
308 | * @return {Level|undefined} |
||
309 | */ |
||
310 | this.removeLevel = function (name) { |
||
311 | var segments = path(name) |
||
312 | if (segments.length === 0) { |
||
313 | throw new Error('You can\'t remove default writer') |
||
314 | } |
||
315 | return levels.remove(segments) |
||
316 | } |
||
317 | |||
318 | /** |
||
319 | * @param {string} name |
||
320 | * |
||
321 | * @return {IWritable} |
||
322 | */ |
||
323 | this.getWriter = function (name) { return writers.retrieve(path(name)) } |
||
324 | |||
325 | /** |
||
326 | * @param {string} [name] Logger name |
||
327 | * @param {IWritable} writer |
||
328 | */ |
||
329 | this.setWriter = function (name, writer) { |
||
330 | if (!writer) { |
||
331 | writer = name |
||
332 | name = null |
||
333 | } |
||
334 | writers.put(path(name), writer) |
||
335 | return self |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * Removes and returns writer under provided path |
||
340 | * |
||
341 | * @throws If attempted to remove root writer |
||
342 | * |
||
343 | * @param {string} name |
||
344 | * @return {IWritable|undefined} |
||
345 | */ |
||
346 | this.removeWriter = function (name) { |
||
347 | var segments = path(name) |
||
348 | if (segments.length === 0) { |
||
349 | throw new Error('You can\'t remove default writer') |
||
350 | } |
||
351 | return writers.remove(segments) |
||
352 | } |
||
353 | |||
354 | /** |
||
355 | * @abstract |
||
356 | * @function Context#create |
||
357 | * @param {string} name |
||
358 | * @param {Level} [threshold] |
||
359 | * @param {IWritable} [writer] |
||
360 | * @return {T} |
||
361 | */ |
||
362 | } |
||
363 | |||
375 |
This check looks for functions where a
return
statement is found in some execution paths, but not in all.Consider this little piece of code
The function
isBig
will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined
.This behaviour may not be what you had intended. In any case, you can add a
return undefined
to the other execution path to make the return value explicit.